blob: fbd6d6cb7ea0c870d3b993fc80beca94498c6473 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include "genetic/population.h"
#include "genetic/phenotype.h"
#include <bu/mutexlocker.h>
Genetic::Population::Population() :
uNextId( 0 ),
uTime( 0 )
{
}
Genetic::Population::~Population()
{
for( PhenotypeHash::iterator i = hPhenotype.begin(); i; i++ )
delete *i;
}
Genetic::PhenotypeId Genetic::Population::addPhenotype(
Genetic::Phenotype *pNew )
{
Bu::MutexLocker ml( mGeneral );
if( !pNew->isActive() )
pNew->setCreated( uTime, uNextId++ );
hPhenotype.insert( pNew->getId(), pNew );
return pNew->getId();
}
bool Genetic::Population::hasProperty( Genetic::PhenotypeId id,
const Bu::String &sKey ) const
{
Bu::MutexLocker ml( mGeneral );
return hPhenotype.get( id )->hasProperty( sKey );
}
Bu::Variant Genetic::Population::getProperty(
Genetic::PhenotypeId id, const Bu::String &sKey ) const
{
Bu::MutexLocker ml( mGeneral );
return hPhenotype.get( id )->getProperty( sKey );
}
void Genetic::Population::setProperty( Genetic::PhenotypeId id,
const Bu::String &sKey, Bu::Variant vValue )
{
Bu::MutexLocker ml( mGeneral );
hPhenotype.get( id )->setProperty( sKey, vValue );
}
void Genetic::Population::delPhenotype( PhenotypeId id )
{
Bu::MutexLocker ml( mGeneral );
delete hPhenotype.get( id );
hPhenotype.erase( id );
}
Genetic::Phenotype *Genetic::Population::takePhenotype( PhenotypeId id )
{
Bu::MutexLocker ml( mGeneral );
Phenotype *pRet = hPhenotype.get( id );
hPhenotype.erase( id );
return pRet;
}
void Genetic::Population::clear()
{
Bu::MutexLocker ml( mGeneral );
for( PhenotypeHash::iterator i = hPhenotype.begin(); i; i++ )
delete *i;
hPhenotype.clear();
}
Genetic::PhenotypeId Genetic::Population::timestep()
{
Bu::MutexLocker ml( mGeneral );
return (++uTime);
}
Genetic::PhenotypeId Genetic::Population::time() const
{
Bu::MutexLocker ml( mGeneral );
return uTime;
}
|